<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="txt">
    <script>
        // 防抖
        function debounce(fn,delay){
            var timer=0;
            return function(){
                let self=this;
                clearInterval(timer);
                timer=setInterval(function(){
                    fn.bind(self)();
                },delay)
            }
        }

        // 节流
        function throttle(fn,delay){
            var firstTime=Date.now();
            return function(){
                var curTime=Date.now();
                if(curTime-firstTime>=delay){
                    fn.bind(this)();
                    firstTime=curTime;
                }
            }
        }

        var oTxt=document.querySelector("#txt");
        oTxt.oninput=throttle(function(){
            console.log(this.value);
        },400)
    </script>
</body>
</html>